package view.card
{
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import global.GameType;
	
	import model.card.ICardData;
	
	public class AbsCard extends Sprite implements ICard
	{
		protected var data:ICardData;
		protected var _playState:int = -1;//是否抽出来
		
		
		public function AbsCard()
		{
			super();
			//initListeners();
		}
		
		public function get id():int
		{
			return data.id;
		}
		
		private function initListeners():void
		{
			addEventListener(MouseEvent.CLICK,onMouseClick);
		}
		
		private function onMouseClick(event:MouseEvent):void
		{
			
		}
		
		public function get type():int
		{
			return data.type;
		}
		
		public function get value():int
		{
			return data.value;
		}
		
		public function updateData(cardData:ICardData):void
		{
			data = cardData;
			_playState =  data.playState;
			data.addEventListener(Event.CHANGE,onChange);
		}
		
		private function onChange(event:Event):void
		{
			if (_playState == data.playState)
			{
				return;
			}
			if (data.playState == GameType.CARD_PLAY_STATE_IN)
			{
				this.y += 15;
				
			}
			else
			{
				this.y -= 15;
				
			}
			_playState = data.playState;
		}
		
		public function get self():DisplayObject
		{
			return this;
		}
		
		public function get playState():int
		{
			return data.playState;
		}
		
		public function set playState(v:int):void
		{
			if (data.playState == v)
			{
				return;
			}
			data.playState = v;
			
		}
		
		public function destroy():void
		{
			data.removeEventListener(Event.CHANGE,onChange);
			data = null;
			removeEventListener(MouseEvent.CLICK,onMouseClick);
		}
	}
}